//
//  CustomCollectionVC.m
//  ShopDemo
//
//  Created by Sunshine on 2018/7/12.
//  Copyright © 2018年 飞扬的青春. All rights reserved.
//

#import "CustomCollectionVC.h"
#import "FirstOneCollectionCell.h"
@interface CustomCollectionVC ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@property(nonatomic,strong)UICollectionView *listCollectionview;


@end

@implementation CustomCollectionVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self crearCollectionview];
}

-(void)crearCollectionview{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    [layout setScrollDirection:UICollectionViewScrollDirectionVertical];
    self.listCollectionview = [[ UICollectionView alloc ] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) collectionViewLayout :layout];
    [self.view addSubview:self.listCollectionview];
    if (kScreenHeight == 812) {
        self.listCollectionview.sd_layout
        .bottomSpaceToView(self.view, 34);
    }
    self.listCollectionview.delegate = self;
    self.listCollectionview.dataSource = self;
    self.listCollectionview.backgroundColor = [UIColor whiteColor];
    [self.listCollectionview registerClass :[ FirstOneCollectionCell class ] forCellWithReuseIdentifier : @"twocell" ];
    
    [self.view addSubview:self.listCollectionview];
    
}

#pragma mark--------------------UICollectionViewDelegateFlowLayout,UICollectionViewDelegate, UICollectionViewDataSource
//cell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.contentArray.count;
}
//
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    FirstOneCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"twocell" forIndexPath:indexPath];
    NSDictionary *dic = self.contentArray[indexPath.row];
    NSURL *url = [NSURL URLWithString:[MethodClass returnUrlSetStrWSDLURL:dic[@"GOODS_PIC"]]];
    [cell.titImageview sd_setImageWithURL:url];
    cell.titlab.text = [NSString stringWithFormat:@"%@",dic[@"CATEGORY_NAME"]];
    
    return cell;
    
}
#pragma mark-------------------布局代理
//设置每个cell的宽和高
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake(kScreenWidth/3 -1, kScreenWidth/3+30*kJLXWidthScale);
}
//设置分区缩进
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(8*kJLXWidthScale, 0, 8*kJLXWidthScale, 0);
}
//设置每个分区之间最小的行间距和列间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return 1;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 1;
}
#pragma mark--------------------------cell点击事件
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
}


@end
